﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace code
{
    public partial class Form1 : Form
    {
        private Time time;//实例化计时器类，用来刷新时间显示
        private Alarms alarm = new Alarms();//实例化闹钟时间类，其中存有用户设置的闹钟时间
        private bool flag1 = true;
        private bool flag2 = true;//这两个标签用来判断两个按钮分别点击了奇数次还是偶数次，以显示不同文本
        public Form1()
        {
            InitializeComponent();
            time = new Time();
            time.SetTick(Timer_Tick);//调用事件处理方法
            alarm.SetAlarm(textBox.Text);//开启应用时为了不使alarm中alarms为空，需要立即设置一次
            textBox.ReadOnly = false;//闹钟设置界面一开始为不可见
        }

        private void Timer_Tick(object sender, EventArgs e)//事件处理方法
        {
            TimeNow.Text = DateTime.Now.ToLongTimeString().ToString();//展示当前时间
            if (alarm.Contians(TimeNow.Text))//判断当前是否为闹钟时间
            {
                MessageBox.Show("您设定的闹钟到点！！！");
            }
        }
        private void SetAlarm_Click(object sender, EventArgs e)//“设置闹钟”按钮功能实现
        {
            if (flag2 == true)
            {
                textBox.Visible = flag2;
                SetAlarm.Text = "完成设置";
                flag2 = false;
            }
            else
            {
                textBox.Visible = flag2;
                SetAlarm.Text = "设置闹钟";
                flag2 = true;
                alarm.SetAlarm(textBox.Text);
            }
        }
        private void ShowAlarms_Click(object sender, EventArgs e)//“查看闹钟”按钮功能实现
        {
            if (flag1 == true)
            {
                textBox.Visible = flag1;
                ShowAlarms.Text = "关闭查看";
                flag1 = false;
            }
            else
            {
                textBox.Visible = flag1;
                ShowAlarms.Text = "查看闹钟";
                flag1 = true;
            }
        }
        private void CloseAlarm_Click(object sender, EventArgs e)//“关闭闹钟”按钮功能实现
        {
            time.Stop();
            this.Close();   
        }
    }
}
